#
# sensor lib Makefile
#

ifeq ($(PARAM_FILE), )
	PARAM_FILE:=../../../../Makefile.param
	include $(PARAM_FILE)
endif

ifeq ($(MPP_BUILD), y)
EXT_PATH := $(SDK_PATH)/mpp/$(EXTDRV)
else
EXT_PATH := $(SDK_PATH)/mpp/extdrv
endif

ISP_PATH := $(SDK_PATH)/mpp/component/isp
LIBPATH = $(ISP_PATH)/lib
OBJPATH = ./obj

# GPIO-I2C or I2C
GPIO_I2C?=N

ifeq ($(GPIO_I2C),Y)
HI_GPIO_I2C:=HI_GPIO_I2C
else
HI_GPIO_I2C:=HI_GPIO_XXX
endif


ARFLAGS = rcv
ARFLAGS_SO = -shared -fPIC -o
CFLAGS  = -Wall -fPIC -D$(HI_FPGA) -D$(HI_GPIO_I2C)
CFLAGS  += -O2

ifeq ($(HIGDB),HI_GDB)
CFLAGS += -g
endif

ISP_INC := $(ISP_PATH)/include
INC := -I$(REL_INC) -I$(ISP_INC)

ifeq ($(GPIO_I2C), Y)
        INC += -I$(EXT_PATH)/gpio-i2c-32bit
	INC += -I$(EXT_PATH)/gpio-i2c
else
        INC += -I$(EXT_PATH)/i2c
        INC += -I$(EXT_PATH)/hi_i2c
endif

COMPILE = $(CC) $(CFLAGS) $(DFLAGS) -lm

$(OBJPATH)/%.o: ./%.c
	@[ -e $(LIBPATH) ] || mkdir $(LIBPATH)
	@[ -e $(OBJPATH) ] || mkdir $(OBJPATH)
	@$(COMPILE) -o $@ -c $< $(INC)

SRCS = $(wildcard ./*.c)
OBJS = $(SRCS:%.c=%.o)
OBJS := $(OBJS:./%=obj/%)

TARGETLIB := $(LIBPATH)/libsns_9m034.a
TARGETLIB_SO := $(LIBPATH)/libsns_9m034.so

all:$(TARGETLIB)
$(TARGETLIB):$(OBJS)
	@mkdir -p $(LIBPATH)
	@($(AR) $(ARFLAGS) $(TARGETLIB) $(OBJS))
	@($(CC) $(ARFLAGS_SO) $(TARGETLIB_SO) $(OBJS))

clean:
	@$(RM) -rf $(TARGETLIB) $(OBJS)
	@$(RM) -rf $(LIBPATH) $(OBJPATH)
